import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;

public class DomParse {
    /**
     * 基于okhttp和jsoup的网页解析
     * okhttp在网络请求方面有优势
     * @param args
     */
    public static void main(String[] args) throws IOException {
        String url="https://www.hao123.com/";
        String baseUrl="https://blog.csdn.net";
        OkHttpClient client=new OkHttpClient();
        Request request=new Request.Builder().url(url).build();
        Response response=client.newCall(request).execute();

        if (response.isSuccessful()){
            Document document= Jsoup.parse(response.body().string());
            Elements link=document.getElementsByTag("a");
            for (Element e:link){
                System.out.println(e.text()+" : "+e.attr("href"));
            }
        }
    }
}
